package com.knife.hospital.controller;

import com.knife.hospital.config.BaseResponse;


import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.*;


import com.knife.hospital.model.user.UserRegisterResponse;
import com.knife.hospital.model.user.UserRegisterRequest;
import com.knife.hospital.model.user.UserLoginResponse;
import com.knife.hospital.model.user.UserLoginRequest;

import com.knife.hospital.service.user.UserLoginService;
import com.knife.hospital.service.user.UserRegisterService;

import javax.annotation.Resource;

@Controller
@CrossOrigin
@ResponseBody
@BaseResponse
@RestController
public class UserController {
    @Resource
    private UserLoginService userLoginService;
    @Resource
    private UserRegisterService userRegisterService;

    @PostMapping(value = "api/user/register")
    public UserRegisterResponse userRegisterFunction(@RequestBody UserRegisterRequest userRegisterRequest) {
        UserRegisterResponse userRegisterResponse;
        try {
            userRegisterResponse = userRegisterService.userRegisterFunction(userRegisterRequest);
        } catch (Exception e) {
            throw e;
        }
        return userRegisterResponse;
    }

    @PostMapping(value = "api/user/login")
    public UserLoginResponse userLoginFunction(@RequestBody UserLoginRequest userLoginRequest) {
        System.out.println(userLoginRequest);
        return userLoginService.userLoginFunction(userLoginRequest);
    }
}